package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

public class Login {

    private List<UserDetails> userDetailsList = new ArrayList<UserDetails>();
    private String username, password;
    private IO io;

    public Login(IO io){
        this.io = io;
        Initialize();
    }

    private void Initialize() {
        userDetailsList.add(new UserDetails("BM","Twu123","Bongani","bm@twu.com","10002312"));
        userDetailsList.add(new UserDetails("Sibo","Sibo123","Sibongile","bsibo@twu.com","123126677"));
    }

    public List<UserDetails> getUserDetailsList()
    {
        return userDetailsList;
    }

    public boolean loginValidator() {
       boolean results = false;
        for( UserDetails user: getUserDetailsList()){
                 io.display("Please login, username");
                 username =  io.nextLine();
                 io.display("Enter password ");
                 password = io.nextLine();

              if (!(username.contains(user.getUsername()) && (password.contains(user.getPassword())))){
                    continue;
              } else{
                  results = true;
                  break;
              }
        }
        return results;
    }
}
